﻿using System;
using System.Collections.Generic;
using System.Text;
using UIShell.OSGi;
using UIShell.OSGi.Core.Service;
using Pasys.PresentationCore;

namespace Pasys.Document
{
    public class Activator : IBundleActivator
    {
        private ExtensionHooker _extensionHooker;

        public void Start(IBundleContext context)
        {
            var _extensionManager = context.GetFirstOrDefaultService<IExtensionManager>();
            _extensionHooker = new ExtensionHooker(_extensionManager);
            var setManager = new SystemSettingManager();
            context.AddService<ISettingManager>(setManager);
             

            var extensionChangeHandler = new ExtensionChangeHandler(new SettingViewProviderBuilder(),
                                          settingViewProvider => setManager.Register((ISettingViewProvider)settingViewProvider),
                                          settingViewProvider => setManager.UnRegister((ISettingViewProvider)settingViewProvider));

            _extensionHooker.HookExtension(ExtensionPointNames.SystemSetting, extensionChangeHandler);
        }

        public void Stop(IBundleContext context)
        {
            //todo:
        }
    }
}
